﻿<%@ WebHandler Language="C#" Class="yepay" %>
using Models;
using System;
using System.Web;
using Newtonsoft.Json;
using System.Web.Configuration;
using WxPayAPI;
using System.Linq;
using Newtonsoft.Json.Linq;
using System.IO;

public class yepay : IHttpHandler {


    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";

        //token: oONIh0XW7FIxBOBPKBzqYJg5iUAw
        //money: 99
        //remark: %E5%9C%A8%E7%BA%BF%E5%85%85%E5%80%BC
        //payName: %E5%9C%A8%E7%BA%BF%E6%94%AF%E4%BB%98
        //nextAction: %7B%7D



        var money=HttpContext.Current.Request.Form["money"];
        var openid=HttpContext.Current.Request.Form["token"];
        var orderId=HttpContext.Current.Request.Form["orderId"];
        var payName=HttpContext.Current.Request.Form["payName"];


        DateTime mytime = DateTime.Now.AddDays(1);
       


        Entities mydb = new Entities();

        var  myprice =money.ToString();// Lt.OLastPrice.ToString();
    


        var myOrderID =Convert.ToInt16(orderId);

          

                    U_CZ mybm = new U_CZ();
                   mybm.UGuid = openid;//人
         
                    mybm.CZMoney = -Convert.ToDecimal(money);
                    mybm.CZTime = DateTime.Now;
                    mybm.CZPayType = "支付"+payName;
                    mybm.CZstat = 1;
                    mybm.UShareGuid = orderId;
                    mydb.U_CZ.Add(mybm);
            
        
            
            
                      var orderid = mydb.T_OrderInfo.SingleOrDefault(p => p.NId == myOrderID);

                    if (orderid.NPayState != 1)
                    { 
                    orderid.DPayDate = DateTime.Now;
                    orderid.NPayState = 1;
                    }

                            mydb.SaveChanges();

        var  code = 1;
        var msg = "付款成功";
        var time = DateTime.Now;



        context.Response.Write(JsonConvert.SerializeObject(new {code,msg,time}));

        HttpContext.Current.Response.End();
        //context.Response.Write("Hello World");


    }

  





    public bool IsReusable {
        get {
            return false;
        }
    }

}